

cc.Class({
    extends: cc.Component,

    properties: {

    },
    timePromptFade(){
        this.timePrompt.runAction(cc.scaleTo(0.3,0,1).easing(cc.easeBackIn()))
    },
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},
    
    start () {
        this.timePrompt = this.node.getChildByName("打烊")
        this.time = 0
    },
    labelNumberChange(labelNode,changeText,originNumber,prefix,suffix){
        if(!prefix){
            prefix = ""
        }
        if(!suffix){
            suffix = ""
        }
        this.changeText = changeText
        this.prefix = prefix
        this.suffix = suffix
        this.origintargetChangeText = String(originNumber)
        
        this.labelNumberChangeDuration = 0.4
        this.labelNumberChangeStartTime = this.time
        this.labelNumberChangeLabelNode = labelNode
        this.labelOutlineColor = this.labelNumberChangeLabelNode.getComponent(cc.LabelOutline).color
        labelNode.getComponent(cc.Label).string = prefix
        labelNode.runAction(cc.sequence(
            cc.scaleTo(this.labelNumberChangeDuration/2,1.2,1.2).easing(cc.easeExponentialOut()),
            cc.scaleTo(this.labelNumberChangeDuration/2,1,1).easing(cc.easeExponentialIn())
        ))
        this.start_labelNumberChange = true

    },
    _labelNumberChangeUpadate(){
        if(this.start_labelNumberChange){
            let differTime = this.time - this.labelNumberChangeStartTime
            let r = (255 - this.labelOutlineColor.r)*differTime/this.labelNumberChangeDuration + this.labelOutlineColor.r
            let g = (255 - this.labelOutlineColor.g)*differTime/this.labelNumberChangeDuration + this.labelOutlineColor.g
            let b = (255 - this.labelOutlineColor.b)*differTime/this.labelNumberChangeDuration + this.labelOutlineColor.b

            this.labelNumberChangeLabelNode.getComponent(cc.LabelOutline).color = new cc.Color(r,g,b)//labelOutlineColor.r
            let targetChangeText = String(this.changeText)
            let tmpChangeText = ""
            for(let i=0;i<targetChangeText.length;i++){
                if(this.origintargetChangeText.substring(i,i+1)== targetChangeText.substring(i,i+1)){
                    tmpChangeText+=targetChangeText.substr(i,1)
                }else{                    
                    tmpChangeText += Math.floor(Math.random() * 10)//targetChangeText.substr(i,1)
                }
                
            }
            this.labelNumberChangeLabelNode.getComponent(cc.Label).string = this.prefix +tmpChangeText  + this.suffix
            if(differTime >this.labelNumberChangeDuration){
                this.start_labelNumberChange = false
                this.labelNumberChangeLabelNode.getComponent(cc.Label).string = this.prefix + this.changeText + this.suffix
                this.labelNumberChangeLabelNode.getComponent(cc.LabelOutline).color = this.labelOutlineColor
            }
        }
    },
    update (dt) {
        this.time+=dt
        this._labelNumberChangeUpadate()
    },
});
